/*
 * LogFile.h
 *
 *  Created on: 2021年4月5日
 *      Author: san
 */

#ifndef BASE_LOGFILE_H_
#define BASE_LOGFILE_H_

#include "noncopyable.h"
#include "FileUtil.h"
#include "Mutex.h"
#include <memory>

namespace san {

class LogFile :  noncopyable {
public:
	LogFile(const std::string &basename, int flushEveryN = 1024);
	~LogFile();

	void append(const char *logline, int len);
	void flush();
	bool rollFile();

private:
	void append_unlock(const char *logline, int len);

	const std::string basename_;
	const int flushEveryN_;

	int count_;
	std::unique_ptr<MutexLock> mutex_;
	std::unique_ptr<AppendFile> file_;
};

} /* namespace san */

#endif /* BASE_LOGFILE_H_ */
